import 'package:ati_package/core/utils/ati_assets.dart';
import 'package:ati_package/core/utils/ati_color.dart';
import 'package:ati_package/core/utils/ati_font.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart' show Get, GetNavigation;
import 'package:qr_flutter/qr_flutter.dart';

import '../../../common/widgets/ati_base_dialog.dart';

class InviteFriendsView extends StatefulWidget {
  const InviteFriendsView({super.key});

  @override
  State<InviteFriendsView> createState() => _InviteFriendsViewState();
}

class _InviteFriendsViewState extends State<InviteFriendsView> {
  @override
  Widget build(BuildContext context) {
    return AtiBaseDialog(
      child: IntrinsicHeight(
        child: Column(
          children: [
            Container(
              // width: Get.width - 60.r.r,
              height: (Get.width - 60.r) * 1.4,
              // margin: EdgeInsets.symmetric(horizontal: 25.r),
              padding: EdgeInsets.only(top: 50.r),

              decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(
                    AtiAssets.userInvitefriendsBg,
                    package: 'ati_package',
                  ),
                ),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    '邀请好友得奖励',
                    style: TextStyle(
                      color: AtiColor.textColor1,
                      fontSize: AtiFont.font18,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                  SizedBox(height: 7.5.r),
                  Text(
                    '邀请越多，奖励越多',
                    style: TextStyle(
                      color: AtiColor.textColor1,
                      fontSize: AtiFont.font12,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  _buildUserInfosWidget(),
                ],
              ),
            ),
            buildFootBtn(),
          ],
        ),
      ),
    );
  }

  _buildUserInfosWidget() {
    return Container(
      padding: EdgeInsets.only(top: 85.r, left: 35.r, right: 35.r),
      child: Column(
        children: [
          Row(
            children: [
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  CircleAvatar(
                    radius: 22.5.r,
                    backgroundColor: const Color(0xFFC23A8E),
                    child: Text(
                      '浪子'.substring(0, 1),
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 22.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  SizedBox(width: 12.5.r),
                  Text(
                    '幼稚园日记',
                    style: TextStyle(
                      fontSize: 14.sp,
                      color: Colors.black87,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  SizedBox(width: 2.5.r),
                  Text(
                    'UID：324252356',
                    style: TextStyle(
                      fontSize: 14.sp,
                      color: Colors.black87,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ],
              ),
              Spacer(),
              QrImageView(
                data: 'https://example.com/user/12345',
                version: QrVersions.auto,
                size: 70.r,
                backgroundColor: Colors.white,
                eyeStyle: const QrEyeStyle(
                  eyeShape: QrEyeShape.square, // 👈 改成方形，视觉更规整
                  color: Colors.black,
                ),
                dataModuleStyle: const QrDataModuleStyle(
                  dataModuleShape: QrDataModuleShape.square, // 👈 与眼形保持一致
                  color: Colors.black,
                ),
              ),
            ],
          ),
          SizedBox(height: 50.r),
          Text(
            '我的专属邀请码',
            style: TextStyle(
              fontSize: 12.sp,
              color: Colors.black87,
              fontWeight: FontWeight.w600,
            ),
          ),
          SizedBox(height: 12.5.r),

          Container(
            height: 45.r,
            width: double.infinity,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Color(0xFFEAFFFA),
              borderRadius: BorderRadius.circular(10.r),
            ),
            child: Text(
              '567990',
              style: TextStyle(
                fontSize: 22.sp,
                color: Colors.black87,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
          SizedBox(height: 12.5.r),
          Text(
            '复制邀请码',
            style: TextStyle(
              color: AtiColor.primary,
              fontSize: AtiFont.font10,
              fontWeight: FontWeight.w600,
            ),
          ),
        ],
      ),
    );
  }

  buildFootBtn() {
    bool _saving = false;
    return GestureDetector(
      onTap: () {
        setState(() => _saving = true);
      },
      child: AnimatedContainer(
        margin: EdgeInsets.symmetric(vertical: 20.r, horizontal: 30.r),

        duration: const Duration(milliseconds: 300),
        width: double.infinity,
        height: 45.h,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(30.r),
          gradient: LinearGradient(
            colors: [const Color(0xFF22C55E), const Color(0xFF10B981)],
          ),
        ),
        child: Center(
          child: _saving == true
              ? SizedBox(
                  width: 22.5.r,
                  height: 22.5.r,
                  child: const CircularProgressIndicator(color: Colors.white),
                )
              : Text(
                  '下载邀请码',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 14.sp,
                    fontWeight: FontWeight.w600,
                  ),
                ),
        ),
      ),
    );
  }
}
